package com.yinhe.group.lck.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yinhe.group.lck.domain.YhDatum;
import com.yinhe.group.lck.service.IYhDatumService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;

import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author yinhe
 * @date 2023-02-11
 */
@RestController
@RequestMapping("/system/datum")
public class YhDatumController extends BaseController
{
    @Autowired
    private IYhDatumService yhDatumService;

    /**
     * 查询【请填写功能名称】列表
     */

    @GetMapping("/list")
    public TableDataInfo list(YhDatum yhDatum)
    {
        startPage();
        List<YhDatum> list = yhDatumService.selectYhDatumList(yhDatum);
        return getDataTable(list);
    }

    @Log(title = "资料台账", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:datum:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YhDatum> util = new ExcelUtil<YhDatum>(YhDatum.class);
        List<YhDatum> mapList = util.importExcel(file.getInputStream());
        String message = yhDatumService.importContract(mapList, updateSupport);
        return AjaxResult.success(message);
    }


    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:datum:export')")
    @Log(title = "资料信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhDatum yhDatum)
    {
        List<YhDatum> list = yhDatumService.selectYhDatumList(yhDatum);
        ExcelUtil<YhDatum> util = new ExcelUtil<YhDatum>(YhDatum.class);
        util.exportExcel(response, list, "资料信息数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhDatumService.selectYhDatumById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:datum:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhDatum yhDatum)
    {
        return toAjax(yhDatumService.insertYhDatum(yhDatum));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:datum:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhDatum yhDatum)
    {
        return toAjax(yhDatumService.updateYhDatum(yhDatum));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:datum:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhDatumService.deleteYhDatumByIds(ids));
    }
}
